@extends('layouts.layout')

@section('header')

    <title>实名认证</title>

    <link rel="stylesheet" type="text/css" href="{{URL::asset('static/css/addAddress.css')}}"/>
    <link rel="stylesheet" type="text/css" href="{{URL::asset('static/css/picker.css')}}"/>

@endsection

@section('content')
    <form class="form">
    	<div class="formview clearfix">
    		<span>姓名:</span>
    		<input type="text" name="name" autocomplete="off" value="{{ $name }}" placeholder="请输入姓名" />
    	</div>
    	<div class="password formview">
    		<span>手机号码:</span>
    		<input type="text" name="mobile" autocomplete="off" value="{{ $mobile }}" placeholder="请输入手机号" />
    	</div>
    	<div class="password formview">
    		<span>身份证号:</span>
    		<input type="text" name="id_card" autocomplete="off" value="{{ $idCard }}" placeholder="请输入身份证号" />
    	</div>
    </form>
    <a href="javascript:;" class="add_address">修改认证</a>

@endsection

@section('script')
    <script type="text/javascript">

        $(function(){
            $(".add_address").click(function(){
                var data = $(".form").serialize();
                data =toJson(decodeURIComponent(data,true));
                if (!data.name.trim()) {
            		layer.open({
            		    content: '请填写姓名!'
            		    ,skin: 'msg'
            		    ,time: 1
            		  });
                	return false;
                }else if (!data.mobile.trim()) {
            		layer.open({
            		    content: '请填写手机号!'
            		    ,skin: 'msg'
            		    ,time: 1
            		  });
                	return false;
                }else if (!(/^(((13[0-9]{1})|(16[0-9]{1})|(19[0-9]{1})|(15([0-9]{1}))|(18[0-9]{1})|(17+(0|1|2|4|5|3|6|7|8))|(14+(5|6|7|8|9)))+\d{8})$/
                        .test(data.mobile))) {
            		layer.open({
            		    content: '手机号格式不正确!'
            		    ,skin: 'msg'
            		    ,time: 1
            		  });
                    return false;
                }else if (!data.id_card.trim()) {
            		layer.open({
            		    content: '请填写身份证号!'
            		    ,skin: 'msg'
            		    ,time: 1
            		  });
                	return false;
                }
                commonAjax({type:"post",url:'/my/saveInfo',data},function(msg){

                    setTimeout(function(){
                        layer.open({
                            content: '提交成功!'
                            ,skin: 'msg'
                            ,time: 2
                            ,end:function(){
                                window.history.go(-1)
                            }
                        });
                    })


                })
                return false;
            })

            //		将字符串转为json
            function toJson(data) {
            	data = data.split('&')
            	var json = {}
            	$.each(data, function(index, value) {
            		var arr = value.split('=');
            		json[arr[0]] = arr[1]
            	});
            	return json
            }
        })

    </script>

@endsection
